<?php
include "../Service/degreesService.php";

if(isset($_GET["action"]))
    $action = $_GET["action"];
else
    $action = "show";
if($action == "show")
{
    $result = getdegrees();
    $n = 0;
    while($row = mysql_fetch_array($result))
    {
        $degree['id'] = $row["DEGREE_ID"];
        $degree['title'] = $row["DEGREE_TITLE"];
        $degree['descript'] = $row["DEGREE_DESCRIPTION"];
        $arrDegree[] = $degree;
        $n++;
    }
}
else if($action == "added")
{
    $degree['title'] = $_POST["title"];
    $degree['descript'] = $_POST["descript"];
    $result = insertDegrees($degree);
    echo "<script>window.location.href='../admin/mod.php?page=degrees'</script>";
}
else if($action == "deleted")
{
    $id = $_GET['id'];
    $result = deleteDegree($id);
    if(!$result)
        echo "<script>alert('Khong the thuc hien')</script>";    
    echo "<script>window.location.href='../admin/mod.php?page=degrees'</script>";
}
else if ($action == "edit")
{
    $id = $_GET["id"];
    $result = getDegreesById($id);
    $degree['id'] = $result["DEGREE_ID"];
    $degree['title'] = $result["DEGREE_TITLE"];
    $degree['descript'] = $result["DEGREE_DESCRIPTION"];
}
else if($action == "edited"){
    $degree['id'] = $_GET["id"];
    $degree['title'] = $_POST["title"];
    $degree['role'] = $_POST["role"];
    $degree['descript'] = $_POST["descript"];
    $result = editDegree($degree);
    if(!$result)
        echo "<script>alert('Khong the thuc hien')</script>";    
    echo "<script>window.location.href='../admin/mod.php?page=degrees'</script>";
}
function showDegrees(){
    $result = getdegrees();
    while($row = mysql_fetch_array($result))
    {
        $degree['id'] = $row["DEGREE_ID"];
        $degree['title'] = $row["DEGREE_TITLE"];
        $degree['descript'] = $row["DEGREE_DESCRIPTION"];
        $arrDegree[] = $degree;
    }
    return $arrDegree;
}
?>